package cn.aitrox.ry.app.web.controller.anno;

import cn.aitrox.ry.app.web.vo.anno.lesion.result.out.AlrCreateOutVo;
import cn.aitrox.ry.bean.RespResult;
import cn.aitrox.ry.service.anno.dto.anno.lesion.result.in.AlrLesionUpdateInDto;
import cn.aitrox.ry.service.anno.dto.anno.lesion.result.in.AlrMaskCreateInDto;
import cn.aitrox.ry.service.anno.dto.anno.lesion.result.in.AlrMaskUpdateInDto;
import cn.aitrox.ry.service.anno.dto.anno.lesion.result.in.AlrPointCreateInDto;
import cn.aitrox.ry.service.anno.dto.anno.lesion.result.in.AlrPointUpdateInDto;
import cn.aitrox.ry.service.anno.dto.anno.result.out.LesionResultDto;
import cn.aitrox.ry.service.anno.feign.LesionResultFeign;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class LesionResultController {

    @Autowired
    @Lazy
    private LesionResultFeign lesionResultFeign;

    @PostMapping(value = "/anno/lesion/result/point")
    public RespResult<AlrCreateOutVo> pointCreate(@Validated @RequestBody AlrPointCreateInDto input) {
        RespResult<Integer> respResult = lesionResultFeign.pointCreate(input);
        if(!respResult._isOk()) {
            return RespResult.secByError(respResult.getCode(), respResult.getMsg());
        }

        Integer alrId = respResult.getData();

        return RespResult.ok(new AlrCreateOutVo(alrId));
    }

    @PutMapping(value = "/anno/lesion/result/point")
    public RespResult pointUpdate(@Validated @RequestBody AlrPointUpdateInDto input) {
        return lesionResultFeign.pointUpdate(input);
    }

    @DeleteMapping(value = "/anno/lesion/result/{alrId}")
    public RespResult delete(@Validated @PathVariable("alrId") Integer alrId) {
        return lesionResultFeign.delete(alrId);
    }

    @PostMapping(value = "/anno/lesion/result/mask")
    public RespResult<AlrCreateOutVo> maskCreate(@Validated @RequestBody AlrMaskCreateInDto input) {
        RespResult<Integer> respResult = lesionResultFeign.maskCreate(input);
        if(!respResult._isOk()) {
            return RespResult.secByError(respResult.getCode(), respResult.getMsg());
        }

        Integer alrId = respResult.getData();

        return RespResult.ok(new AlrCreateOutVo(alrId));
    }

    @PutMapping(value = "/anno/lesion/result/mask")
    public RespResult maskUpdate(@Validated @RequestBody AlrMaskUpdateInDto input) {
        return lesionResultFeign.maskUpdate(input);
    }

    @PutMapping(value = "/anno/lesion/result/lesion/update")
    public RespResult<LesionResultDto> lesionUpdate(@Validated @RequestBody AlrLesionUpdateInDto input) {
        return lesionResultFeign.lesionUpdate(input);
    }

}
